package cn.ywang.spring.orm.framework;

/**
 * @author BeatificWang
 * @date 2019/5/4 23:40
 */
public class Order {
	/**
	 * 升序还是降序
	 */
	private boolean isAsc;
	/**
	 * 哪个字段升序，哪个字段降序
	 */
	private String propertyName;

	@Override
	public String toString() {
		return this.propertyName + ' ' + (this.isAsc ? "asc" : "desc");
	}

	/**
	 * Constructor for Order.
	 */
	protected Order(String propertyName, boolean isAsc) {
		this.propertyName = propertyName;
		this.isAsc = isAsc;
	}

	/**
	 * Ascending order
	 *
	 * @param propertyName
	 * @return Order
	 */
	public static Order asc(String propertyName) {
		return new Order(propertyName, true);
	}

	/**
	 * Descending order
	 *
	 * @param propertyName
	 * @return Order
	 */
	public static Order desc(String propertyName) {
		return new Order(propertyName, false);
	}
}
